from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-27 14:04:54.804277
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 27, Jul, 2022
Time: 14:05:02
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.9418
Nobs: 730.000 HQIC: -50.2896
Log likelihood: 9203.03 FPE: 1.16043e-22
AIC: -50.5081 Det(Omega_mle): 1.02669e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299100 0.056655 5.279 0.000
L1.Burgenland 0.107392 0.037157 2.890 0.004
L1.Kärnten -0.106998 0.019707 -5.429 0.000
L1.Niederösterreich 0.207998 0.077819 2.673 0.008
L1.Oberösterreich 0.106677 0.075878 1.406 0.160
L1.Salzburg 0.254020 0.039756 6.389 0.000
L1.Steiermark 0.042636 0.051872 0.822 0.411
L1.Tirol 0.108692 0.042068 2.584 0.010
L1.Vorarlberg -0.062579 0.036273 -1.725 0.084
L1.Wien 0.048180 0.067115 0.718 0.473
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053860 0.118338 0.455 0.649
L1.Burgenland -0.031737 0.077612 -0.409 0.683
L1.Kärnten 0.047066 0.041163 1.143 0.253
L1.Niederösterreich -0.177872 0.162545 -1.094 0.274
L1.Oberösterreich 0.409163 0.158490 2.582 0.010
L1.Salzburg 0.288427 0.083041 3.473 0.001
L1.Steiermark 0.108446 0.108347 1.001 0.317
L1.Tirol 0.311430 0.087870 3.544 0.000
L1.Vorarlberg 0.026338 0.075765 0.348 0.728
L1.Wien -0.027932 0.140188 -0.199 0.842
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188765 0.028968 6.516 0.000
L1.Burgenland 0.090175 0.018999 4.746 0.000
L1.Kärnten -0.008942 0.010076 -0.887 0.375
L1.Niederösterreich 0.261778 0.039790 6.579 0.000
L1.Oberösterreich 0.138271 0.038797 3.564 0.000
L1.Salzburg 0.046109 0.020328 2.268 0.023
L1.Steiermark 0.020590 0.026523 0.776 0.438
L1.Tirol 0.093282 0.021510 4.337 0.000
L1.Vorarlberg 0.056247 0.018547 3.033 0.002
L1.Wien 0.114885 0.034317 3.348 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111108 0.029487 3.768 0.000
L1.Burgenland 0.045867 0.019339 2.372 0.018
L1.Kärnten -0.014028 0.010257 -1.368 0.171
L1.Niederösterreich 0.188487 0.040502 4.654 0.000
L1.Oberösterreich 0.301399 0.039492 7.632 0.000
L1.Salzburg 0.109717 0.020692 5.302 0.000
L1.Steiermark 0.104522 0.026997 3.872 0.000
L1.Tirol 0.105785 0.021895 4.831 0.000
L1.Vorarlberg 0.068139 0.018879 3.609 0.000
L1.Wien -0.021632 0.034931 -0.619 0.536
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.129792 0.053720 2.416 0.016
L1.Burgenland -0.049803 0.035232 -1.414 0.157
L1.Kärnten -0.040971 0.018686 -2.193 0.028
L1.Niederösterreich 0.165037 0.073788 2.237 0.025
L1.Oberösterreich 0.140451 0.071947 1.952 0.051
L1.Salzburg 0.289306 0.037697 7.675 0.000
L1.Steiermark 0.036258 0.049185 0.737 0.461
L1.Tirol 0.163625 0.039889 4.102 0.000
L1.Vorarlberg 0.099764 0.034394 2.901 0.004
L1.Wien 0.068774 0.063639 1.081 0.280
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054791 0.042735 1.282 0.200
L1.Burgenland 0.039375 0.028028 1.405 0.160
L1.Kärnten 0.050933 0.014865 3.426 0.001
L1.Niederösterreich 0.217877 0.058699 3.712 0.000
L1.Oberösterreich 0.296139 0.057234 5.174 0.000
L1.Salzburg 0.043810 0.029988 1.461 0.144
L1.Steiermark 0.000864 0.039127 0.022 0.982
L1.Tirol 0.143598 0.031732 4.525 0.000
L1.Vorarlberg 0.072625 0.027360 2.654 0.008
L1.Wien 0.080765 0.050625 1.595 0.111
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174891 0.051059 3.425 0.001
L1.Burgenland -0.002613 0.033487 -0.078 0.938
L1.Kärnten -0.062732 0.017761 -3.532 0.000
L1.Niederösterreich -0.082052 0.070133 -1.170 0.242
L1.Oberösterreich 0.191709 0.068383 2.803 0.005
L1.Salzburg 0.058254 0.035829 1.626 0.104
L1.Steiermark 0.234870 0.046748 5.024 0.000
L1.Tirol 0.498743 0.037913 13.155 0.000
L1.Vorarlberg 0.045227 0.032690 1.384 0.167
L1.Wien -0.053936 0.060486 -0.892 0.373
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170679 0.058708 2.907 0.004
L1.Burgenland -0.007551 0.038503 -0.196 0.845
L1.Kärnten 0.066185 0.020421 3.241 0.001
L1.Niederösterreich 0.204367 0.080639 2.534 0.011
L1.Oberösterreich -0.070976 0.078627 -0.903 0.367
L1.Salzburg 0.207895 0.041197 5.046 0.000
L1.Steiermark 0.122216 0.053751 2.274 0.023
L1.Tirol 0.071752 0.043592 1.646 0.100
L1.Vorarlberg 0.118348 0.037587 3.149 0.002
L1.Wien 0.119080 0.069547 1.712 0.087
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.361286 0.033819 10.683 0.000
L1.Burgenland 0.007398 0.022180 0.334 0.739
L1.Kärnten -0.023772 0.011764 -2.021 0.043
L1.Niederösterreich 0.217130 0.046452 4.674 0.000
L1.Oberösterreich 0.198449 0.045293 4.381 0.000
L1.Salzburg 0.043063 0.023732 1.815 0.070
L1.Steiermark -0.014133 0.030964 -0.456 0.648
L1.Tirol 0.105126 0.025112 4.186 0.000
L1.Vorarlberg 0.070410 0.021652 3.252 0.001
L1.Wien 0.037151 0.040063 0.927 0.354
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039890 0.139351 0.191094 0.150933 0.117579 0.103287 0.062738 0.216050
Kärnten 0.039890 1.000000 -0.006881 0.132842 0.039404 0.094504 0.433673 -0.053375 0.098013
Niederösterreich 0.139351 -0.006881 1.000000 0.334763 0.141912 0.293915 0.094883 0.176834 0.314377
Oberösterreich 0.191094 0.132842 0.334763 1.000000 0.228010 0.324653 0.175191 0.164106 0.260952
Salzburg 0.150933 0.039404 0.141912 0.228010 1.000000 0.142044 0.111217 0.144064 0.123782
Steiermark 0.117579 0.094504 0.293915 0.324653 0.142044 1.000000 0.145633 0.137332 0.071079
Tirol 0.103287 0.433673 0.094883 0.175191 0.111217 0.145633 1.000000 0.110743 0.142629
Vorarlberg 0.062738 -0.053375 0.176834 0.164106 0.144064 0.137332 0.110743 1.000000 -0.001903
Wien 0.216050 0.098013 0.314377 0.260952 0.123782 0.071079 0.142629 -0.001903 1.000000